Distinguish null reference production from null pointer dereference in UB checks#158796
Distinguish null reference production from null pointer dereference in UB checks#158796raushan728 wants to merge 1 commit into
Conversation
|
This PR changes rustc_public cc @oli-obk, @celinval, @ouz-a, @makai410 Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @vakaras
cc @bjorn3 Some changes occurred to the CTFE machinery |
|
|
|
Requested reviewer is already assigned to this pull request. Please choose another assignee. |
| //@ run-crash | ||
| //@ compile-flags: -C debug-assertions | ||
| //@ error-pattern: null pointer dereference occurred | ||
| //@ error-pattern: null reference formed |
There was a problem hiding this comment.
"formed" is not a verb we use for this anywhere else I think. The reference calls it "producing" an invalid value, maybe use that?
There was a problem hiding this comment.
thanks! i'll update the message to use produced to exact match the terminology.
Introduce a dedicated panic for null reference production to distinguish producing a reference from a null pointer from an actual null pointer dereference. This emits a dedicated panic message for null reference production while preserving the existing panic for actual dereferences.
Closes #154044
This change distinguishes null reference production from actual null pointer dereferences in the UB checks.
Producing a reference from a null pointer (for example,
&*ptr) is undefined behavior even if no memory is dereferenced. This change introduces a dedicatedAssertKind::NullReferenceConstructedand runtime panic so these cases produce a more accurate diagnostic while preserving the existing panic for actual null pointer dereferences.Summary
AssertKind::NullReferenceConstructed.panic_null_reference_constructedand its lang item.NullPointerDereferencefor actual dereferences.